package com.ujiuye.web;

import com.ujiuye.entity.Student;
import com.ujiuye.service.StudentService;
import com.ujiuye.utils.PageUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@MultipartConfig
@WebServlet("/queryStuByPage")
public class QueryStuPageServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决中文乱码
//        req.setCharacterEncoding("utf-8");
//        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        // 获取页面发送过来的当前页参数
        String curPage = req.getParameter("curPage");
        // 调用分页方法
        StudentService ss = new StudentService();
        // 获取总记录数
        int rows = ss.queryNum();
        PageUtils pu = new PageUtils(rows,curPage);
        List<Student> list = ss.queryStuPage(pu);
        // 绑定数据
        req.setAttribute("list",list);
        req.setAttribute("pu",pu);
        // 转发
        req.getRequestDispatcher("queryStu.jsp").forward(req,resp);
    }
}
